home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt3sp4.arc / SETPARMC.PAS < prev    next >
Pascal/Delphi Source File  |  1985-10-07  |  43KB  |  1,135 lines

  1. (*----------------------------------------------------------------------*)
  2. (*           Read_Config_File --- Read configuration file               *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. OVERLAY FUNCTION Read_Config_File : BOOLEAN;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Function:   Read_Config_File                                     *)
  10. (*                                                                      *)
  11. (*     Purpose:    Reads parameters from primary PibTerm config. file   *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Read_Ok := Read_Config_File : BOOLEAN;                        *)
  16. (*                                                                      *)
  17. (*           Read_Ok --- TRUE if config file found, else FALSE.         *)
  18. (*                                                                      *)
  19. (*     Calls:   Get_Config_File_Line                                    *)
  20. (*                                                                      *)
  21. (*----------------------------------------------------------------------*)
  22.  
  23. VAR
  24.    Ival       : INTEGER;
  25.    OK_To_Read : BOOLEAN;
  26.    I          : INTEGER;
  27.    J          : INTEGER;
  28.    Param_Num  : INTEGER;
  29.    Param_Str  : AnyStr;
  30.    Param_Ival : INTEGER;
  31.    Param_Rval : REAL;
  32.  
  33. (*--------------------------------------------------------------------------*)
  34. (*      Get_Config_File_Line --- Get one parameter line from config file    *)
  35. (*--------------------------------------------------------------------------*)
  36.  
  37. FUNCTION Get_Config_File_Line(  VAR Param_Num:  INTEGER;
  38.                                 VAR Param_Str:  AnyStr;
  39.                                 VAR Param_Ival: INTEGER;
  40.                                 VAR Param_Rval: REAL ) : BOOLEAN;
  41.  
  42. (*--------------------------------------------------------------------------*)
  43. (*                                                                          *)
  44. (*     Function:  Get_Config_File_Line                                      *)
  45. (*                                                                          *)
  46. (*     Purpose:   Reads and interprets one line of configuration file       *)
  47. (*                                                                          *)
  48. (*     Calling Sequence:                                                    *)
  49. (*                                                                          *)
  50. (*        QGot := Get_Config_File_Line(  VAR Param_Num:  INTEGER;           *)
  51. (*                                       VAR Param_Str:  AnyStr;            *)
  52. (*                                       VAR Param_Ival: INTEGER;           *)
  53. (*                                       VAR Param_Rval: REAL ) : BOOLEAN;  *)
  54. (*                                                                          *)
  55. (*           Param_Num  --- parameter number of this line                   *)
  56. (*           Param_Str  --- string value of parameter                       *)
  57. (*           Param_Ival --- Integer value of parameter                      *)
  58. (*           Param_Rval --- Real value of parameter                         *)
  59. (*                                                                          *)
  60. (*           Qgot       --- TRUE if configuration line returned;            *)
  61. (*                          FALSE if end-of-file encountered on             *)
  62. (*                          configuration file.                             *)
  63. (*                                                                          *)
  64. (*     Calls:  None                                                         *)
  65. (*                                                                          *)
  66. (*--------------------------------------------------------------------------*)
  67.  
  68. VAR
  69.    I:      INTEGER;
  70.    S:      AnyStr;
  71.    PName:  STRING[2];
  72.  
  73. BEGIN (* Get_Config_File_Line *)
  74.                                    (* Initialize parameter values *)
  75.    Param_Num  := 0;
  76.    Param_Str  := '';
  77.    Param_Ival := 0;
  78.    Param_Rval := 0;
  79.  
  80.    IF NOT EOF( Config_File ) THEN
  81.       BEGIN
  82.  
  83.          Get_Config_File_Line := TRUE;
  84.  
  85.                                    (* Indicate line from configuration file *)
  86.          READLN( Config_File , S );
  87.  
  88.          S         := S + '    ';
  89.          I         := 0;
  90.          PName     := UpCase( S[1] ) + UpCase( S[2] );
  91.          Param_Str := Trim( COPY( S, 4, LENGTH( S ) - 3 ) );
  92.  
  93.                                    (* Search for parameter *)
  94.          REPEAT
  95.             I := I + 1;
  96.          UNTIL ( I > Max_Param_Names ) OR ( PName = Param_Names[I] );
  97.  
  98.                                    (* If found, convert to numeric if *)
  99.                                    (* appropriate                     *)
  100.  
  101.          IF I <= Max_Param_Names THEN
  102.             BEGIN
  103.                Param_Num := I;
  104.                FOR I := 1 TO LENGTH( Param_Str ) DO
  105.                   IF Param_Str[I] IN ['0'..'9'] THEN
  106.                      Param_Ival := Param_Ival * 10 + ORD( Param_Str[I] ) -
  107.                                                      ORD( '0' );
  108.                IF LENGTH( Param_Str ) > 0 THEN
  109.                   IF ( UpCase(Param_Str[1]) = 'Y' ) THEN
  110.                      Param_Ival := 1;
  111.                Param_Rval := Param_Ival;
  112.             END;
  113.  
  114.       END
  115.  
  116.    ELSE
  117.       Get_Config_File_Line := FALSE;
  118.  
  119. END   (* Get_Config_File_Line *);
  120.  
  121. (*--------------------------------------------------------------------------*)
  122.  
  123. BEGIN (* Read_Config_File *)
  124.                                    (* Assign configuration file *)
  125.  
  126.   ASSIGN( Config_File , Home_Dir + 'PIBTERM.CNF' );
  127.        (*$I-*)
  128.   RESET( Config_File );
  129.        (*$I+*)
  130.  
  131.   OK_To_Read := ( Int24Result = 0 );
  132.  
  133.   IF NOT OK_To_Read THEN           (* If config file missing, prompt *)
  134.                                    (* user for input                 *)
  135.  
  136.      BEGIN (* No configuration file *)
  137.  
  138.         WRITELN;
  139.         WRITELN('Can''t find configuration file PIBTERM.CNF');
  140.  
  141.      END   (* No configuration file *)
  142.  
  143.   ELSE                            (* PIBTERM.CNF exists -- read it *)
  144.      BEGIN  (* Config file exists *)
  145.  
  146.         WRITELN('Reading configuration file PIBTERM.CNF');
  147.  
  148.         WHILE( Get_Config_File_Line( Param_Num, Param_Str, Param_Ival,
  149.                                      Param_Rval ) ) DO
  150.            Set_Parameter( Param_Num, Param_Ival, Param_Rval, Param_Str );
  151.  
  152.         CLOSE( Config_File );
  153.  
  154.      END    (* Config file exists *);
  155.  
  156.    Read_Config_File := OK_To_Read;
  157.  
  158. END   (* Read_Config_File *);
  159.  
  160. (*--------------------------------------------------------------------------*)
  161. (*      Read_Config_From_Script --- Read parameters from script buffer      *)
  162. (*--------------------------------------------------------------------------*)
  163.  
  164. OVERLAY PROCEDURE Read_Config_From_Script;
  165.  
  166. (*----------------------------------------------------------------------*)
  167. (*                                                                      *)
  168. (*     Function:   Read_Config_From_Script                              *)
  169. (*                                                                      *)
  170. (*     Purpose:    Reads parameters from PibTerm script buffer          *)
  171. (*                                                                      *)
  172. (*     Calling Sequence:                                                *)
  173. (*                                                                      *)
  174. (*        Read_Config_From_Script;                                      *)
  175. (*                                                                      *)
  176. (*     Calls:   Get_Config_File_Line_From_Script                        *)
  177. (*                                                                      *)
  178. (*----------------------------------------------------------------------*)
  179.  
  180. VAR
  181.    Ival       : INTEGER;
  182.    OK_To_Read : BOOLEAN;
  183.    I          : INTEGER;
  184.    J          : INTEGER;
  185.    Param_Num  : INTEGER;
  186.    Param_Str  : AnyStr;
  187.    Param_Ival : INTEGER;
  188.    Param_Rval : REAL;
  189.  
  190. (*--------------------------------------------------------------------------*)
  191. (* Get_Config_File_Line_From_Script --- Get one param. line from script     *)
  192. (*--------------------------------------------------------------------------*)
  193.  
  194. FUNCTION Get_Config_File_Line_From_Script(  VAR Param_Num:  INTEGER;
  195.                                             VAR Param_Str:  AnyStr;
  196.                                             VAR Param_Ival: INTEGER;
  197.                                             VAR Param_Rval: REAL ) : BOOLEAN;
  198.  
  199. (*--------------------------------------------------------------------------*)
  200. (*                                                                          *)
  201. (*     Function:  Get_Config_File_Line_From_Script                          *)
  202. (*                                                                          *)
  203. (*     Purpose:   Reads and interprets one line of script buffer            *)
  204. (*                                                                          *)
  205. (*     Calling Sequence:                                                    *)
  206. (*                                                                          *)
  207. (*        QGot := Get_Config_File_Line_From_Script( VAR Param_Num: INTEGER; *)
  208. (*                                                  VAR Param_Str:  AnyStr; *)
  209. (*                                                  VAR Param_Ival: INTEGER;*)
  210. (*                                                  VAR Param_Rval: REAL )  *)
  211. (*                                                  : BOOLEAN;              *)
  212. (*                                                                          *)
  213. (*           Param_Num  --- parameter number of this line                   *)
  214. (*           Param_Str  --- string value of parameter                       *)
  215. (*           Param_Ival --- Integer value of parameter                      *)
  216. (*           Param_Rval --- Real value of parameter                         *)
  217. (*                                                                          *)
  218. (*           Qgot       --- TRUE if configuration line returned;            *)
  219. (*                          FALSE if end-of-buffer encountered on           *)
  220. (*                          script buffer.                                  *)
  221. (*                                                                          *)
  222. (*     Calls:  None                                                         *)
  223. (*                                                                          *)
  224. (*--------------------------------------------------------------------------*)
  225.  
  226. VAR
  227.    I:      INTEGER;
  228.    J:      INTEGER;
  229.    L:      INTEGER;
  230.    PName:  STRING[2];
  231.  
  232. BEGIN (* Get_Config_File_Line_From_Script *)
  233.  
  234.                                    (* Initialize parameter values *)
  235.    Param_Num  := 0;
  236.    Param_Str  := '';
  237.    Param_Ival := 0;
  238.    Param_Rval := 0;
  239.                                    (* Move to next slot in script *)
  240.  
  241.    Script_Buffer_Pos := Script_Buffer_Pos + 1;
  242.  
  243.                                    (* See if it's PARAM           *)
  244.  
  245.     IF ( PibTerm_Command_Table_2[ Script_Buffer^[Script_Buffer_Pos] ]
  246.          = ParamSy ) THEN
  247.          BEGIN
  248.  
  249.             Get_Config_File_Line_From_Script := TRUE;
  250.  
  251.             Script_Buffer_Pos := Script_Buffer_Pos + 1;
  252.             J                 := Script_Buffer_Pos;
  253.             PName             := UpCase( Script_Buffer^[J]   ) +
  254.                                  UpCase( Script_Buffer^[J+1] );
  255.  
  256.             L                 := Script_Buffer^[J+2];
  257.             Script_Buffer_Pos := J + 2;
  258.  
  259.             FOR J := 1 TO L DO
  260.                BEGIN
  261.                   Script_Buffer_Pos := Script_Buffer_Pos + 1;
  262.                   Param_Str         := Param_Str +
  263.                                        CHR( Script_Buffer^[Script_Buffer_Pos] );
  264.                END;
  265.  
  266.             Writelne( 'Set parameter ' + PName + ' to ' + Param_Str , TRUE );
  267.  
  268.                                    (* Search for parameter *)
  269.  
  270.             I                 := 0;
  271.  
  272.             REPEAT
  273.                I := I + 1;
  274.             UNTIL ( I > Max_Param_Names ) OR ( PName = Param_Names[I] );
  275.  
  276.                                    (* If found, convert to numeric if *)
  277.                                    (* appropriate                     *)
  278.  
  279.             IF I <= Max_Param_Names THEN
  280.                BEGIN
  281.                   Param_Num := I;
  282.                   FOR I := 1 TO LENGTH( Param_Str ) DO
  283.                      IF Param_Str[I] IN ['0'..'9'] THEN
  284.                         Param_Ival := Param_Ival * 10 + ORD( Param_Str[I] ) -
  285.                                                         ORD( '0' );
  286.                   IF ( LENGTH( Param_Str ) > 0 ) THEN
  287.                      IF ( UpCase( Param_Str[1] ) = 'Y' ) THEN
  288.                         Param_Ival := 1;
  289.                   Param_Rval := Param_Ival;
  290.                END;
  291.  
  292.       END
  293.  
  294.    ELSE
  295.       BEGIN
  296.          Get_Config_File_Line_From_Script := FALSE;
  297.          Script_Buffer_Pos                := Script_Buffer_Pos - 1;
  298.       END;
  299.  
  300. END   (* Get_Config_File_Line_From_Script *);
  301.  
  302. (*--------------------------------------------------------------------------*)
  303.  
  304. BEGIN (* Read_Config_From_Script *)
  305.  
  306.                                    (* Point to 'Paramsy' entry *)
  307.  
  308.    Script_Buffer_Pos := Script_Buffer_Pos - 1;
  309.  
  310.                                    (* Pick up all 'Paramsy' entries *)
  311.  
  312.    WHILE( Get_Config_File_Line_From_Script( Param_Num, Param_Str, Param_Ival,
  313.                                             Param_Rval ) ) DO
  314.       Set_Parameter( Param_Num, Param_Ival, Param_Rval, Param_Str );
  315.  
  316. END   (* Read_Config_From_Script *);
  317.  
  318. (*----------------------------------------------------------------------*)
  319. (*                Get_Other_Files --- read initialization files         *)
  320. (*----------------------------------------------------------------------*)
  321.  
  322. OVERLAY PROCEDURE Get_Other_Files;
  323.  
  324. (*----------------------------------------------------------------------*)
  325. (*                                                                      *)
  326. (*     Procedure: Get_Other_Files                                       *)
  327. (*                                                                      *)
  328. (*     Purpose:   Reads other initialization files than primary config. *)
  329. (*                file PIBTERM.CNF.                                     *)
  330. (*                                                                      *)
  331. (*     Calling Sequence:                                                *)
  332. (*                                                                      *)
  333. (*        Get_Other_Files;                                              *)
  334. (*                                                                      *)
  335. (*     Calls:                                                           *)
  336. (*                                                                      *)
  337. (*----------------------------------------------------------------------*)
  338.  
  339. VAR
  340.    I                    : INTEGER;
  341.  
  342. (*----------------------------------------------------------------------*)
  343. (*            Read_Prefix_File --- Read dialing prefix file             *)
  344. (*----------------------------------------------------------------------*)
  345.  
  346. PROCEDURE Read_Prefix_File;
  347.  
  348. (*----------------------------------------------------------------------*)
  349. (*                                                                      *)
  350. (*     Procedure:  Read_Prefix_File                                     *)
  351. (*                                                                      *)
  352. (*     Purpose:    Reads dialing prefix file                            *)
  353. (*                                                                      *)
  354. (*     Calling Sequence:                                                *)
  355. (*                                                                      *)
  356. (*        Read_Prefix_File;                                             *)
  357. (*                                                                      *)
  358. (*      Calls:   Read_Config_File                                       *)
  359. (*               Read_Prefix_File                                       *)
  360. (*               Read_Phone_Directory                                   *)
  361. (*                                                                      *)
  362. (*----------------------------------------------------------------------*)
  363.  
  364. VAR
  365.    Iprefix    : INTEGER;
  366.    OK_To_Read : BOOLEAN;
  367.    OK_Qmodem  : BOOLEAN;
  368.  
  369. BEGIN (* Read_Prefix_File *)
  370.                                    (* Clear out prefix entries *)
  371.  
  372.    FOR Iprefix := 1 TO Max_Phone_Prefixes DO
  373.       Phone_Prefix_Nos[Iprefix] := '';
  374.  
  375.                                    (* Assign phone prefix file *)
  376.  
  377.    ASSIGN( Phone_Prefix_File , Home_Dir + 'PIBTERM.PRE' );
  378.         (*$I-*)
  379.    RESET( Phone_Prefix_File );
  380.         (*$I+*)
  381.  
  382.    OK_To_Read := ( Int24Result = 0 );
  383.    OK_Qmodem  := FALSE;
  384.  
  385.    IF NOT OK_To_Read THEN
  386.       BEGIN
  387.                                    (* KLUDGE to ensure white text *)
  388.          TextColor( White );
  389.  
  390.          IF YesNo('Can''t find PIBTERM.PRE.  Try using QMODEM.PRE? ') THEN
  391.             BEGIN
  392.  
  393.                ASSIGN( Phone_Prefix_File , 'QMODEM.PRE' );
  394.                     (*$I-*)
  395.                RESET ( Phone_Prefix_File );
  396.                     (*$I+*)
  397.  
  398.                OK_Qmodem := ( IOResult = 0 );
  399.  
  400.                IF NOT OK_Qmodem THEN
  401.                   BEGIN
  402.                      WRITELN;
  403.                      WRITELN('Can''t find QMODEM.PRE either, no prefixes set.');
  404.                   END;
  405.  
  406.             END;
  407.       END;
  408.                                    (* Read prefix entries *)
  409.  
  410.    IF ( OK_To_Read OR Ok_Qmodem ) THEN
  411.       BEGIN
  412.  
  413.          WRITE('Reading phone prefixes from ');
  414.  
  415.          IF Ok_Qmodem THEN
  416.             WRITELN('QMODEM.PRE')
  417.          ELSE
  418.             WRITELN('PIBTERM.PRE');
  419.  
  420.          Iprefix := 1;
  421.  
  422.          REPEAT
  423.             READLN( Phone_Prefix_File , Phone_Prefix_Nos[ Iprefix ] );
  424.             Iprefix := Iprefix + 1;
  425.          UNTIL( EOF( Phone_Prefix_File ) OR ( Iprefix > Max_Phone_Prefixes ) );
  426.  
  427.               (*$I-*)
  428.          CLOSE( Phone_Prefix_File );
  429.               (*$I+*)
  430.  
  431.       END;
  432.                                    (* Write new prefix file *)
  433.  
  434.    IF NOT Ok_To_Read THEN
  435.       BEGIN
  436.  
  437.          ASSIGN( Phone_Prefix_File , Home_Dir + 'PIBTERM.PRE' );
  438.              (*$I-*)
  439.          REWRITE( Phone_Prefix_File );
  440.              (*$I+*)
  441.  
  442.          IF Int24Result <> 0 THEN
  443.             BEGIN
  444.                WRITELN;
  445.                WRITELN('Can''t create new PIBTERM.PRE')
  446.             END
  447.          ELSE
  448.             BEGIN
  449.  
  450.                WRITELN;
  451.                WRITELN('Creating PIBTERM.PRE -- phone prefix file.');
  452.  
  453.                FOR Iprefix := 1 TO Max_Phone_Prefixes DO
  454.                   WRITELN( Phone_Prefix_File , Phone_Prefix_Nos[ Iprefix ] );
  455.  
  456.                CLOSE( Phone_Prefix_File );
  457.  
  458.             END;
  459.  
  460.       END;
  461.  
  462. END   (* Read_Prefix_File *);
  463.  
  464. (*----------------------------------------------------------------------*)
  465. (*        Read_Phone_Directory --- Read phone number directory          *)
  466. (*----------------------------------------------------------------------*)
  467.  
  468. PROCEDURE Read_Phone_Directory;
  469.  
  470. (*----------------------------------------------------------------------*)
  471. (*                                                                      *)
  472. (*     Procedure:  Read_Phone_Directory                                 *)
  473. (*                                                                      *)
  474. (*     Purpose:    Read phone directory entries                         *)
  475. (*                                                                      *)
  476. (*     Calling Sequence:                                                *)
  477. (*                                                                      *)
  478. (*        Read_Phone_Directory;                                         *)
  479. (*                                                                      *)
  480. (*      Calls:   Read_Config_File                                       *)
  481. (*               Read_Prefix_File                                       *)
  482. (*               Read_Phone_Directory                                   *)
  483. (*                                                                      *)
  484. (*----------------------------------------------------------------------*)
  485.  
  486. TYPE
  487.                                    (* Parity type in Qmodem *)
  488.    Check_Bit = ( None, Even );
  489.  
  490.                                    (* QMODEM phone directory file format *)
  491.    Qmodem_Record = RECORD
  492.                       Name:   STRING[25];
  493.                       Number: STRING[14];
  494.                       Speed:  INTEGER;
  495.                       Dbits:  INTEGER;
  496.                       Sbits:  INTEGER;
  497.                       Parity: Check_Bit;
  498.                    END;
  499.                                    (* PC-Talk phone directory file format *)
  500.  
  501.    PCTalk_Record = RECORD
  502.                       Name:    ARRAY[ 1 .. 24 ] OF CHAR;
  503.                       Filler1: ARRAY[ 1 .. 22 ] OF CHAR;
  504.                       Number:  ARRAY[ 1 .. 14 ] OF CHAR;
  505.                       Filler2: ARRAY[ 1 ..  2 ] OF CHAR;
  506.                       Speed:   ARRAY[ 1 ..  4 ] OF CHAR;
  507.                       Parity:  CHAR;
  508.                       Dbits:   CHAR;
  509.                       Sbits:   CHAR;
  510.                       Filler3: ARRAY[ 1 .. 59 ] OF CHAR;
  511.                    End;
  512.  
  513. VAR
  514.    Iphone     : INTEGER;
  515.    OK_To_Read : BOOLEAN;
  516.    CRLF       : Char_2;
  517.    T_String   : AnyStr;
  518.  
  519.                                    (* QMODEM phone directory file      *)
  520.    QmodemF :  FILE OF Qmodem_Record;
  521.  
  522.                                    (* Entry for QMODEM directory file  *)
  523.    Qmodem_Entry : Qmodem_Record;
  524.  
  525.                                    (* PC TALK phone directory file     *)
  526.    PCTalkF :  FILE OF PCTalk_Record;
  527.  
  528.                                    (* Entry for PC Talk directory file *)
  529.    PCTalk_Entry : PCTalk_Record;
  530.  
  531. (*----------------------------------------------------------------------*)
  532. (*   Convert_Qmodem_Directory --- Read Qmodem phone number directory    *)
  533. (*----------------------------------------------------------------------*)
  534.  
  535. FUNCTION Convert_Qmodem_Directory : BOOLEAN;
  536.  
  537. BEGIN (* Convert_Qmodem_Directory *)
  538.  
  539.    Convert_Qmodem_Directory := FALSE;
  540.  
  541.    ASSIGN( QmodemF , 'QMODEM.FON' );
  542.       (*$I-*)
  543.    RESET ( QmodemF );
  544.       (*$I+*)
  545.  
  546.    OK_To_Read := ( IOResult = 0 );
  547.  
  548.    IF NOT OK_To_Read THEN
  549.       BEGIN
  550.          WRITELN;
  551.          WRITELN('Can''t find QMODEM.FON.');
  552.       END
  553.    ELSE
  554.       BEGIN  (* Try converting Qmodem dir. to PibTerm dir. *)
  555.  
  556.          ASSIGN( Phone_File , Home_Dir + 'PIBTERM.FON' );
  557.             (*$I-*)
  558.          REWRITE( Phone_File );
  559.             (*$I+*)
  560.  
  561.          IF Int24Result <> 0 THEN
  562.             WRITELN('Can''t create new PIBTERM.FON from QMODEM.FON')
  563.          ELSE
  564.             BEGIN  (* Convert QMODEM directory to PibTerm dir. *)
  565.  
  566.                WRITELN;
  567.                WRITELN('Converting QMODEM.FON to PIBTERM.FON');
  568.  
  569.                Phone_Entry_Data.Phone_Ender := CRLF;
  570.  
  571.                WITH Phone_Entry_Data, Qmodem_Entry DO
  572.                   REPEAT
  573.  
  574.                      READ( QmodemF , Qmodem_Entry );
  575.  
  576.                      CopyStoA( Name ,   Phone_Name ,   25 );
  577.                      CopyS2AR( Number , Phone_Number , 15 );
  578.  
  579.                      STR ( Speed:5 , T_String );
  580.                      CopyS2AR( T_String , Phone_Baud , 5 );
  581.  
  582.                      STR ( Dbits:1 , T_String );
  583.                      Phone_Databits := T_STRING[1];
  584.  
  585.                      STR ( Sbits:1 , T_String );
  586.                      Phone_StopBits := T_STRING[1];
  587.  
  588.                      CASE Parity OF
  589.                         Even: Phone_Parity := 'E';
  590.                         None: Phone_Parity := 'N';
  591.                         Else  Phone_Parity := 'O';
  592.                      END;
  593.  
  594.                      WRITE( Phone_File , Phone_Entry_Data );
  595.  
  596.                   UNTIL( EOF( QmodemF ) );
  597.  
  598.                CLOSE( Phone_File );
  599.                CLOSE( QmodemF    );
  600.  
  601.                Convert_Qmodem_Directory := TRUE;
  602.  
  603.             END (* Convert QMODEM phone directory *);
  604.  
  605.       END    (* Try Converting QMODEM phone directory *);
  606.  
  607. END   (* Convert_Qmodem_Directory *);
  608.  
  609. (*----------------------------------------------------------------------*)
  610. (*   Convert_PCTalk_Directory --- Read PC TALK phone number directory   *)
  611. (*----------------------------------------------------------------------*)
  612.  
  613. FUNCTION Convert_PCTalk_Directory: BOOLEAN;
  614.  
  615. BEGIN (* Convert_PCTalk_Directory *)
  616.  
  617.    Convert_PCTalk_Directory := FALSE;
  618.  
  619.    ASSIGN( PCTalkF , 'PCTALK.FON' );
  620.       (*$I-*)
  621.    RESET ( PCTalkF );
  622.       (*$I+*)
  623.  
  624.    OK_To_Read := ( IOResult = 0 );
  625.  
  626.    IF NOT OK_To_Read THEN
  627.       BEGIN
  628.          WRITELN;
  629.          WRITELN('Can''t find PCTALK.FON either, no phone numbers set.');
  630.       END
  631.    ELSE
  632.       BEGIN  (* Try converting PC Talk dir. to PibTerm dir. *)
  633.  
  634.          ASSIGN( Phone_File , Home_Dir + 'PIBTERM.FON' );
  635.             (*$I-*)
  636.          REWRITE( Phone_File );
  637.             (*$I+*)
  638.  
  639.          IF Int24Result <> 0 THEN
  640.             WRITELN('Can''t create new PIBTERM.FON from PCTALK.FON')
  641.          ELSE
  642.             BEGIN  (* Convert PCTALK directory to PibTerm dir. *)
  643.  
  644.                WRITELN;
  645.                WRITELN('Converting PCTALK.FON to PIBTERM.FON');
  646.  
  647.                Phone_Entry_Data.Phone_Ender := CRLF;
  648.  
  649.                WITH Phone_Entry_Data, PCTalk_Entry DO
  650.                   REPEAT
  651.  
  652.                      READ( PCTalkF , PCTalk_Entry );
  653.  
  654.                      CopyStoA( Name   , Phone_Name   , 25 );
  655.                      CopyS2AR( Number , Phone_Number , 15 );
  656.                      CopyS2AR( Speed  , Phone_Baud   ,  5 );
  657.  
  658.                      Phone_Databits := Dbits;
  659.                      Phone_StopBits := Sbits;
  660.                      Phone_Parity   := Parity;
  661.  
  662.                      WRITE( Phone_File , Phone_Entry_Data );
  663.  
  664.                   UNTIL( EOF( PCTalkF ) );
  665.  
  666.                CLOSE( Phone_File );
  667.                CLOSE( PCTalkF    );
  668.  
  669.                Convert_PCTalk_Directory := TRUE;
  670.  
  671.             END (* Convert PCTalk phone directory *);
  672.  
  673.       END    (* Try Converting PCTalk phone directory *);
  674.  
  675. END   (* Convert_PCTalk_Directory *);
  676.  
  677. (*----------------------------------------------------------------------*)
  678.  
  679. BEGIN (* Read_Phone_Directory *)
  680.                                    (* Set CR+LF -- ends each phone rec *)
  681.    CRLF[1]  := CHR( CR );
  682.    CRLF[2]  := CHR( LF );
  683.                                    (* Assign phone number file *)
  684.  
  685.    ASSIGN( Phone_File , Home_Dir + 'PIBTERM.FON' );
  686.         (*$I-*)
  687.    RESET( Phone_File );
  688.         (*$I+*)
  689.  
  690.    OK_To_Read := ( Int24Result = 0 );
  691.  
  692.                                    (* Lengthen short dialing directory *)
  693.    IF OK_To_Read THEN
  694.       BEGIN
  695.  
  696.          IF FileSize( Phone_File ) < ( Default_Phone_Number_Size - 1 ) THEN
  697.             BEGIN
  698.  
  699.                WITH Phone_Entry_Data DO
  700.                   BEGIN
  701.  
  702.                      CopyStoA( Dupl( '-' , 25 ) , Phone_Name ,   25 );
  703.                      CopyStoA( ' # ### ###-####' , Phone_Number , 15 );
  704.  
  705.                      Phone_Parity   := COPY( Parity, 1, 1 );
  706.  
  707.                      STR ( Baud_Rate:5 , T_String );
  708.                      CopyStoA( T_String , Phone_Baud , 5 );
  709.  
  710.                      STR ( Data_Bits:1 , T_String );
  711.                      Phone_Databits := T_STRING[1];
  712.  
  713.                      STR ( Stop_Bits:1 , T_String );
  714.                      Phone_StopBits := T_STRING[1];
  715.  
  716.                      Phone_Ender    := CRLF;
  717.  
  718.                   END;
  719.  
  720.                SEEK( Phone_File, FileSize( Phone_File ) );
  721.  
  722.                FOR Iphone := FileSize( Phone_File ) TO Default_Phone_Number_Size DO
  723.                   WRITE( Phone_File , Phone_Entry_Data );
  724.  
  725.                CLOSE( Phone_File );
  726.  
  727.             END;
  728.  
  729.          EXIT;
  730.  
  731.       END;
  732.                                    (* Couldn't read directory          *)
  733.    IF NOT OK_To_Read THEN
  734.       BEGIN
  735.                                    (* KLUDGE to ensure white text *)
  736.          TextColor( White );
  737.  
  738.          IF YesNo('Can''t find PIBTERM.FON.  Try using QMODEM.FON? ') THEN
  739.             OK_To_Read := Convert_Qmodem_Directory;
  740.  
  741.          IF ( NOT OK_To_Read ) THEN
  742.             IF YesNo('Try using PCTALK.FON? ') THEN
  743.                OK_To_Read := Convert_PCTalk_Directory;
  744.  
  745.       END;
  746.                                    (* Create phone directory if needed *)
  747.  
  748.    IF ( NOT OK_To_Read ) THEN
  749.       BEGIN  (* Phone directory doesn't exist *)
  750.  
  751.          ASSIGN( Phone_File , Home_Dir + 'PIBTERM.FON' );
  752.              (*$I-*)
  753.          REWRITE( Phone_File );
  754.              (*$I+*)
  755.  
  756.          IF Int24Result <> 0 THEN
  757.             BEGIN
  758.                WRITELN;
  759.                WRITELN('Can''t create new PIBTERM.FON')
  760.             END
  761.          ELSE
  762.             BEGIN  (* Create phone directory *)
  763.  
  764.                WRITELN;
  765.                WRITELN('Creating PIBTERM.FON -- phone number file.');
  766.  
  767.                WITH Phone_Entry_Data DO
  768.                   BEGIN
  769.  
  770.                      CopyStoA( Dupl( '-' , 25 ) , Phone_Name ,   25 );
  771.                      CopyStoA( ' # ### ###-####' , Phone_Number , 15 );
  772.  
  773.                      Phone_Parity   := COPY( Parity, 1, 1 );
  774.  
  775.                      STR ( Baud_Rate:5 , T_String );
  776.                      CopyStoA( T_String , Phone_Baud , 5 );
  777.  
  778.                      STR ( Data_Bits:1 , T_String );
  779.                      Phone_Databits := T_STRING[1];
  780.  
  781.                      STR ( Stop_Bits:1 , T_String );
  782.                      Phone_StopBits := T_STRING[1];
  783.  
  784.                      Phone_ENDer    := CRLF;
  785.  
  786.                   END;
  787.  
  788.                FOR Iphone := 1 TO Default_Phone_Number_Size DO
  789.                   WRITE( Phone_File , Phone_Entry_Data );
  790.  
  791.                CLOSE( Phone_File );
  792.  
  793.             END    (* Create phone directory *);
  794.  
  795.       END   (* Phone directory doesn't exist *);
  796.  
  797. END   (* Read_Phone_Directory *);
  798.  
  799. (*----------------------------------------------------------------------*)
  800. (*        Read_Function_Keys --- Read function key definitions          *)
  801. (*----------------------------------------------------------------------*)
  802.  
  803. PROCEDURE Read_Function_Keys;
  804.  
  805. (*----------------------------------------------------------------------*)
  806. (*                                                                      *)
  807. (*     Procedure:  Read_Function_Keys                                   *)
  808. (*                                                                      *)
  809. (*     Purpose:    Read function key definitions                        *)
  810. (*                                                                      *)
  811. (*     Calling Sequence:                                                *)
  812. (*                                                                      *)
  813. (*        Read_Function_Keys;                                           *)
  814. (*                                                                      *)
  815. (*      Calls:   Read_Config_File                                       *)
  816. (*               Read_Prefix_File                                       *)
  817. (*               Read_Phone_Directory                                   *)
  818. (*                                                                      *)
  819. (*----------------------------------------------------------------------*)
  820.  
  821. VAR
  822.    Input_Key_File : Text;
  823.    Key_Name       : STRING[3];
  824.    Key_Text       : AnyStr;
  825.    Section_No     : INTEGER;
  826.    Key_Def_Text   : AnyStr;
  827.    Key_Number     : INTEGER;
  828.    L_Text         : INTEGER;
  829.    I              : INTEGER;
  830.    J              : INTEGER;
  831.  
  832. (*----------------------------------------------------------------------*)
  833. (*  Process_Function_Key_Definition --- Process Function Key Definition *)
  834. (*----------------------------------------------------------------------*)
  835.  
  836. PROCEDURE Process_Key_Definition;
  837.  
  838. (*----------------------------------------------------------------------*)
  839. (*                                                                      *)
  840. (*     Procedure:  Process_Key_Definition                               *)
  841. (*                                                                      *)
  842. (*     Purpose:    Process and store key definition string              *)
  843. (*                                                                      *)
  844. (*     Calling Sequence:                                                *)
  845. (*                                                                      *)
  846. (*        Process_Key_Definition;                                       *)
  847. (*                                                                      *)
  848. (*           On entry, Key_Text should have the key definition text     *)
  849. (*           as read from a file.                                       *)
  850. (*                                                                      *)
  851. (*----------------------------------------------------------------------*)
  852.  
  853. (* STRUCTURED *) CONST
  854.    Keypad_Nos:  ARRAY[0..10] OF BYTE
  855.                 = ( 9, 7, 4, 8, 2, 0, 3, 5, 1, 6, 10 );
  856.  
  857. BEGIN (* Process_Key_Definition *)
  858.  
  859.    L_Text         := LENGTH( Key_Text );
  860.  
  861.                                    (* Get key name   *)
  862.  
  863.    Key_Name       := COPY( Key_Text, 1, 2 );
  864.    IF Key_Text[3] <> '=' THEN
  865.       Key_Name := Key_Name + Key_Text[3];
  866.  
  867.                                    (* Choose section *)
  868.    CASE UpCase( Key_Name[1] ) OF
  869.  
  870.       'F': Section_No := 1;
  871.  
  872.       'S': Section_No := 2;
  873.  
  874.       'C': IF UpCase( Key_Name[2] ) = 'K' THEN
  875.               Section_No := 7
  876.            ELSE
  877.               Section_No := 3;
  878.  
  879.       'A': IF UpCase( Key_Name[2] ) = 'K' THEN
  880.               Section_No := 6
  881.            ELSE
  882.               Section_No := 4;
  883.  
  884.       'K': Section_No := 5;
  885.  
  886.       ELSE
  887.            Section_No := 0;
  888.  
  889.    END (* Case *);
  890.                                    (* Key text initially null *)
  891.    Key_Def_Text   := '';
  892.                                    (* Get key number *)
  893.    I              := 2;
  894.    Key_Number     := 0;
  895.  
  896.    WHILE ( I <= L_Text ) AND ( Key_Text[I] <> '=' ) DO
  897.       BEGIN
  898.  
  899.          CASE Key_Text[I] OF
  900.             '0'..'9': Key_Number := Key_Number * 10 + ORD(Key_Text[I]) - ORD('0');
  901.             '.'     : Key_Number := 10;
  902.          END (* Case *);
  903.  
  904.          I          := I + 1;
  905.  
  906.       END;
  907.                                    (* Skip past '=' sign *)
  908.  
  909.    IF Key_Text[I] = '=' THEN I := I + 1;
  910.  
  911.                                    (* Get key text *)
  912.    IF ( L_Text - I + 1 ) > 0 THEN
  913.       Key_Def_Text   := Read_Ctrls( COPY( Key_Text, I, L_Text - I + 1 ) );
  914.  
  915.                                    (* Insert key text in function key *)
  916.                                    (* or keypad key.                  *)
  917.    IF Section_No IN [1..4] THEN
  918.       BEGIN
  919.          IF ( Key_Number > 0 ) AND ( Key_Number < 11 ) THEN
  920.               Function_Keys[ Section_No , Key_Number ] := Key_Def_Text;
  921.       END
  922.    ELSE IF Section_No IN [5..7] THEN
  923.       BEGIN
  924.          IF ( Key_Number >= 0 ) AND ( Key_Number < 11 ) THEN
  925.               Keypad_Keys[ Section_No - 4 , Keypad_Nos[ Key_Number ] ]
  926.                  := Key_Def_Text;
  927.       END;
  928.  
  929. END   (* Process_Key_Definition *);
  930.  
  931. (*----------------------------------------------------------------------*)
  932.  
  933. BEGIN (* Read_Function_Keys *)
  934.                                    (* Attach file with definitions *)
  935.  
  936.    ASSIGN( Input_Key_File , Home_Dir + 'PIBTERM.FNC' );
  937.        (*$I-*)
  938.    RESET ( Input_Key_File );
  939.        (*$I+*)
  940.                                    (* See if openable *)
  941.    IF ( Int24Result = 0 ) THEN
  942.       BEGIN (* File OK, read definitions *)
  943.  
  944.          WRITELN('Reading key definitions from PIBTERM.FNC');
  945.  
  946.          REPEAT
  947.  
  948.             Key_Text       := ' ';
  949.                                    (* Read key definition *)
  950.  
  951.             READLN( Input_Key_File , Key_Text );
  952.  
  953.                                    (* Process it *)
  954.  
  955.             Process_Key_Definition;
  956.  
  957.          UNTIL( EOF( Input_Key_File ) );
  958.  
  959.          CLOSE( Input_Key_File );
  960.  
  961.       END   (* File OK, read definitions *);
  962.  
  963. END   (* Read_Function_Keys *);
  964.  
  965. (*----------------------------------------------------------------------*)
  966. (*        Read_Translate_Table --- Read translate table definitions     *)
  967. (*----------------------------------------------------------------------*)
  968.  
  969. PROCEDURE Read_Translate_Table;
  970.  
  971. (*----------------------------------------------------------------------*)
  972. (*                                                                      *)
  973. (*     Procedure:  Read_Translate_Table                                 *)
  974. (*                                                                      *)
  975. (*     Purpose:    Read translate table definitions                     *)
  976. (*                                                                      *)
  977. (*     Calling Sequence:                                                *)
  978. (*                                                                      *)
  979. (*        Read_Translate_Table;                                         *)
  980. (*                                                                      *)
  981. (*      Calls:   Read_Config_File                                       *)
  982. (*               Read_Prefix_File                                       *)
  983. (*               Read_Phone_Directory                                   *)
  984. (*                                                                      *)
  985. (*----------------------------------------------------------------------*)
  986.  
  987. VAR
  988.    TrTab_File : TEXT;
  989.    I          : INTEGER;
  990.    J          : INTEGER;
  991.  
  992. BEGIN (* Read_Translate_Table *)
  993.  
  994.    ASSIGN( TrTab_File , Home_Dir + 'PIBTERM.TRA' );
  995.       (*$I-*)
  996.    RESET ( TrTab_File );
  997.       (*$I+*)
  998.  
  999.    IF ( Int24Result = 0 ) THEN
  1000.       BEGIN (* File OK, read definition *)
  1001.  
  1002.          WRITELN('Reading translate table from PIBTERM.TRA');
  1003.  
  1004.          REPEAT
  1005.                (*$I-*)
  1006.             READLN( TrTab_File , I, J );
  1007.                (*$I+*)
  1008.             IF Int24Result = 0 THEN
  1009.                IF ( I >= 0 ) AND ( I <= 255 ) AND
  1010.                   ( J >= 0 ) AND ( J <= 255 ) THEN
  1011.                   TrTab[CHR(I)] := CHR( J );
  1012.  
  1013.          UNTIL( EOF( TrTab_File ) );
  1014.  
  1015.       END   (* Get definition from file *);
  1016.  
  1017.    CLOSE( TrTab_File );
  1018.  
  1019. END   (* Read_Translate_Table *);
  1020.  
  1021. (*----------------------------------------------------------------------*)
  1022.  
  1023. BEGIN (* Get_Other_Files *)
  1024.                                    (* Read dialing prefix file        *)
  1025.    Read_Prefix_File;
  1026.                                    (* Read dialing entries            *)
  1027.    Read_Phone_Directory;
  1028.                                    (* Read function key definitions   *)
  1029.    Read_Function_Keys;
  1030.                                    (* Read translate table definitions*)
  1031.    Read_Translate_Table;
  1032.  
  1033. END   (* Get_Other_Files *);
  1034.  
  1035. (*----------------------------------------------------------------------*)
  1036. (*                    Set_Params --- Main code body                     *)
  1037. (*----------------------------------------------------------------------*)
  1038.  
  1039. BEGIN (* Set_Params *)
  1040.                                    (* Don't reset port unless needed *)
  1041.    Reset_Comm_Port   := FALSE;
  1042.                                    (* If comm port changes *)
  1043.    Comm_Port_Changed := FALSE;
  1044.                                    (* Remember current colors *)
  1045.  
  1046.    New_ForeGround_Color := ForeGround_Color;
  1047.    New_BackGround_Color := BackGround_Color;
  1048.    New_Menu_Text_Color  := Menu_Text_Color;
  1049.    New_Menu_Frame_Color := Menu_Frame_Color;
  1050.  
  1051.                                    (* Remember current text mode *)
  1052.  
  1053.    New_Text_Mode        := Text_Mode;
  1054.  
  1055.                                    (* Get parameter values      *)
  1056.    IF First_Time THEN
  1057.       BEGIN
  1058.          Set_Defaults;
  1059.          IF ( NOT Read_Config_File ) THEN
  1060.             BEGIN
  1061.                Get_Default_Params( TRUE );
  1062.                Write_Config_File;
  1063.             END;
  1064.          Get_Other_Files;
  1065.       END
  1066.    ELSE
  1067.       IF ( NOT Use_Script ) THEN
  1068.          Get_Default_Params( FALSE )
  1069.       ELSE
  1070.          Read_Config_From_Script;
  1071.  
  1072.                                    (* Initialize Comm Variables *)
  1073.  
  1074.    IF ( First_Time OR Comm_Port_Changed ) THEN
  1075.       BEGIN
  1076.  
  1077.          Async_Init;
  1078.                                    (* Open Communications Port  *)
  1079.  
  1080.          Set_Params := Async_Open( Comm_Port, Baud_Rate, Parity, Data_Bits,
  1081.                                    Stop_Bits );
  1082.  
  1083.       END
  1084.    ELSE
  1085.       BEGIN
  1086.                                    (* Not 1st time, same port -- *)
  1087.                                    (* reset open port            *)
  1088.          Set_Params := TRUE;
  1089.  
  1090.          Async_Reset_Port( Comm_Port, Baud_Rate, Parity, Data_Bits,
  1091.                            Stop_Bits );
  1092.  
  1093.       END;
  1094.  
  1095.    IF First_Time THEN
  1096.       BEGIN
  1097.                                    (* Clear screen if initial entry *)
  1098.          ClrScr;
  1099.                                    (* Get backscroll buffer if 1st time *)
  1100.  
  1101.          Review_Buffer_Length := 81 * Max_Review_Length;
  1102.  
  1103.          IF Review_Buffer_Length > ( MaxBlockAvail - 32000.0 ) THEN
  1104.             BEGIN
  1105.                Max_Review_Length    := MAX( 0 ,
  1106.                                             TRUNC( ( MaxBlockAvail - 32000.0 ) / 81.0 ) );
  1107.                Review_Buffer_Length := 81 * Max_Review_Length;
  1108.             END;
  1109.  
  1110.          Review_On := ( Max_Review_Length > 0 );
  1111.  
  1112.          IF Review_On THEN
  1113.             GetMem( Review_Buffer , Review_Buffer_Length );
  1114.  
  1115.          Review_Head      := 0;
  1116.          Review_Tail      := 0;
  1117.          Review_Line      := '';
  1118.  
  1119.       END;
  1120.                                    (* Change text mode, colors      *)
  1121.    IF Text_Mode <> New_Text_Mode THEN
  1122.       BEGIN
  1123.          Text_Mode := New_Text_Mode;
  1124.          TextMode( Text_Mode );
  1125.       END;
  1126.  
  1127.    ForeGround_Color := New_ForeGround_Color;
  1128.    BackGround_Color := New_BackGround_Color;
  1129.    Menu_Text_Color  := New_Menu_Text_Color;
  1130.    Menu_Frame_Color := New_Menu_Frame_Color;
  1131.  
  1132.    Set_Global_Colors( ForeGround_Color , BackGround_Color );
  1133.  
  1134. END   (* Set_Params *);
  1135.